package be.vsko.zelfevaluatie.jackson.mapping;

import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.map.annotate.JsonSerialize;

import be.vsko.zelfevaluatie.framework.Component;
import be.vsko.zelfevaluatie.framework.Section;
import be.vsko.zelfevaluatie.framework.Statement;
import be.vsko.zelfevaluatie.framework.Survey;
import be.vsko.zelfevaluatie.rest.RoaServlet;

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class ExtendedSurvey extends SimpleSurvey {
	private List<MappedComponent> components = new ArrayList<MappedComponent>();

	public ExtendedSurvey(Survey survey, RoaServlet servlet) {
		super(survey, servlet);
		for(Component comp: survey.getComponents())
			components.add(new MappedComponent(comp, servlet));
	}
	
	public List<MappedComponent> getComponents() {
		return components;
	}
	
	@Override
	public String getHref() {
		return null;
	}
	
	private class MappedComponent {
		private String name;
		private List<MappedSection> sections = new ArrayList<MappedSection>();
		
		public MappedComponent(Component component, RoaServlet servlet) {
			this.name = component.getName();
			for(Section sec: component.getSections())
				this.sections.add(new MappedSection(sec, servlet));
		}
		
		public String getName() {
			return name;
		}

		public List<MappedSection> getSections() {
			return sections;
		}

		private class MappedSection {
			private String name;
			private List<SimpleStatement> statements = new ArrayList<SimpleStatement>();
			
			public MappedSection(Section section, RoaServlet servlet) {
				this.name = section.getName();
				for(Statement st: section.getStatements())
					this.statements.add(new SimpleStatement(st, servlet));
			}

			public String getName() {
				return name;
			}

			public List<SimpleStatement> getStatements() {
				return statements;
			}
		}
	}
}
